<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/Sources/bootstrap/css/bootstrap.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/Sources/js/tools/jquery-1.11.3.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/Sources/bootstrap/js/bootstrap.js"></script>
<style type="text/css">
body{
text-align:center;


}
.table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td
{
vertical-align: middle;
}
.sp_div{
	width:250px;
	height:30px;
}
.Guess_text{
background:red
}
.h_six{
        font-family: fantasy;
}
.div_e{
width:185px
}
.row_six{
width:140px
}
.click_style{
	display: none
}
.inptut_text{
width:40px
}
</style>
</head>
<body>
<button id="recount">重新计算</button>
	<table class="table table-bordered  table-hover">
		<thead>
			<tr>
				<td>比赛编号</td>
				<td>比赛开始日期</td>
				<td>下注截至日期</td>
				
				<td>赛事名称</td>
				<td>主队</td>
				<td>主队排名</td>
				<td>客队</td>
				<td>客队排名</td>
				<td>sp</td>
				<td>E的各种结果</td>
				<td>最近六场该赛制积分</td>
			</tr>
		</thead>
		<tbody>
			
		</tbody>
	</table>
</body>
<script>
	$(function() {
		
		var home_paim,guest_paim;
		
		
		//	日期转换格式
		function ChangeDateFormat(jsondate) {
			jsondate = jsondate.replace("/Date(", "").replace(")/", "");
			if (jsondate.indexOf("+") > 0) {
				jsondate = jsondate.substring(0, jsondate.indexOf("+"));
			} else if (jsondate.indexOf("-") > 0) {
				jsondate = jsondate.substring(0, jsondate.indexOf("-"));
			}
			var date = new Date(parseInt(jsondate, 10));
			var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1)
					: date.getMonth() + 1;
			var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date
					.getDate();
			var hours = date.getHours() < 10 ? "0" + date.getHours() : date
					.getHours();
			var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes()
					: date.getMinutes();
			var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds()
					: date.getSeconds();
			return date.getFullYear() + "年" + month + "月" + currentDate + "日"
					+ " " + hours + ":" + minutes + ":" + seconds;
		}

		//	请求数据
		$.ajax({
			url: 'getGame',
			method: 'GET',
			dataType: 'json'
		}).done(function(results) {
			//console.log(results);
			$.each(results, function(name, game) { //	game层				
				var game_id = $('<td>', {}).text(game.game_id);
				var beginDate = $('<td>', {}).text(ChangeDateFormat(game.beginDate.toString()));
				var endtime = $('<td>', {}).text(ChangeDateFormat(game.endtime.toString()));
				var league = $('<td>', {}).text(game.league);
				var homeTeam_name = $('<td>', {}).text(game.homeTeam.homeTeam_name);
				var text_hpaim = $('<input>', {
					'type': 'text',
					'class': 'inptut_text',
					'id': 'homepaim_' + game.game_id,
					'value': game.homeTeam.paim
				});
				var home_paim = $('<td>', {}).append(text_hpaim);
				var guestTeam_name = $('<td>', {}).text(game.guestTeam.guestTeam_name);
				var text_gpaim = $('<input>', {
					'type': 'text',
					'class': 'inptut_text',
					'id': 'gusetpaim_' + game.game_id,
					'value': game.guestTeam.paim
				});
				var guest_paim = $('<td>', {}).append(text_gpaim);

				//	sps
				var sp1_concedePoints = $('<div>', { 'class': 'col-sm-3' }).text(game.sps[0].concedePoints)
				var sp1_div3 = $('<div>', {
					'class': 'col-sm-3',
					'id': 'sp_3_' + game.game_id
				}).text(game.sps[0].sp_3);
				var sp1_div1 = $('<div>', {
					'class': 'col-sm-3',
					'id': 'sp_1_' + game.game_id
				}).text(game.sps[0].sp_1);
				var sp1_div0 = $('<div>', {
					'class': 'col-sm-3',
					'id': 'sp_0_' + game.game_id
				}).text(game.sps[0].sp_0);
				var sp1_div = $('<div>', {
					'class': 'row'
				}).append(sp1_concedePoints).append(sp1_div3).append(sp1_div1).append(sp1_div0);

				var sp2_concedePoints = $('<div>', { 'class': 'col-sm-3' }).text(game.sps[1].concedePoints)
				var sp2_div3 = $('<div>', {
					'class': 'col-sm-3',
					'id': 'spr_3_' + game.game_id
				}).text(game.sps[1].sp_3);
				var sp2_div1 = $('<div>', {
					'class': 'col-sm-3',
					'id': 'spr_1_' + game.game_id
				}).text(game.sps[1].sp_1);
				var sp2_div0 = $('<div>', {
					'class': 'col-sm-3',
					'id': 'spr_0_' + game.game_id
				}).text(game.sps[1].sp_0);
				var sp2_div = $('<div>', {
					'class': 'row'
				}).append(sp2_concedePoints).append(sp2_div3).append(sp2_div1).append(sp2_div0);
				var sp_div = $('<div>', {
					'class': 'sp_div'
				}).append(sp1_div).append(sp2_div)
				var sp = $('<td>', {}).append(sp_div);

				var ze = $('<div>', { 'class': 'col-sm-4 ze', 'id': 'ze_' + game.game_id }).text(game.es[0].result.toString().substr(0, 5));
				var pe = $('<div>', { 'class': 'col-sm-4 pe', 'id': 'pe_' + game.game_id }).text(game.es[1].result.toString().substr(0, 5));
				var ke = $('<div>', { 'class': 'col-sm-4 ke', 'id': 'ke_' + game.game_id }).text(game.es[2].result.toString().substr(0, 5));

				var div_es = $('<div>', {
					'class': 'row div_e'
				}).append(ze).append(pe).append(ke);
				var es = $('<td>', {}).append(div_es);

				var homeTeam_sixIntegrals = game.homeTeam.sixIntegrals;
				var guestTeam_sixIntegrals = game.guestTeam.sixIntegrals
				if(game.homeTeam.homeTeam_number == null) {
					homeTeam_sixIntegrals = -1;
				}
				if(game.guestTeam.guestTeam_num == null) {
					guestTeam_sixIntegrals = -1;
				}

				var z_six = $('<div>', {
					'class': 'col-sm-2'
				}).text(homeTeam_sixIntegrals);
				var k_six = $('<div>', {
					'class': 'col-sm-2'
				}).text(guestTeam_sixIntegrals);
				var d_six = $('<div>', {
					'class': 'col-sm-2'
				});
				var r_six = $('<div>', {
					'class': 'col-sm-6'
				});
				if(guestTeam_sixIntegrals != -1 && homeTeam_sixIntegrals != -1) {
					var dif = game.homeTeam.sixIntegrals - game.guestTeam.sixIntegrals;
					if(dif > 0) { //主强
						z_six.addClass('h_six');

					}
					if(dif < 0) { //客强
						k_six.addClass('h_six');
					}
					d_six.text(dif);
					if(Math.abs(dif) >= 6) { //当对赛的两队相差为6或者6以上，最高分球队获胜
						if(dif > 0) { r_six.text('胜(3)') };
						if(dif < 0) { r_six.text('负(0)') };
					} else if(Math.abs(dif) == 5) { //若主队分最高，主队胜，若客队分高，主队胜平
						if(dif > 0) { r_six.text('胜(3)') };
						if(dif < 0) { r_six.text('胜/平(3/1)') };
					} else if(Math.abs(dif) <= 4 && Math.abs(dif) >= 2) {
						if(dif > 0) { r_six.text('胜(3)') };
						if(dif < 0) { r_six.text('负(0)') };
					} else if(Math.abs(dif) >= 0 && Math.abs(dif) < 2) {
						r_six.text('胜/平(3/1)');
					}
				}

				var div_six = $('<div>', {
					'class': 'row row_six'
				}).append(z_six).append(k_six).append(d_six).append(r_six);
				var td_six = $('<td>', {}).append(div_six);

				$('<tr>', {})
					.append(game_id)
					.append(beginDate)
					.append(endtime)
					.append(league)
					.append(homeTeam_name)
					.append(home_paim)
					.append(guestTeam_name)
					.append(guest_paim)
					.append(sp)
					.append(es)
					.append(td_six)
					.appendTo('.table tbody');
			});

		});
		
		
		//	tr click事件
	$('tr').on('dblclick',function(e){
		//$(this).toggleClass('click_style');
	});
	
	$('#recount').on('click',function(){
	
		alert("aa");
	})
	
	})
</script>
</html>